package ConfigManage_Singleton_06;

import java.util.HashMap;
import java.util.Map;

public class ConfigManager {
    private static volatile ConfigManager instance;
    private final Map<String, String> configMap;

    private ConfigManager() {
        configMap = new HashMap<>();
        load();
    }

    public static ConfigManager getInstance() {
        if (instance == null) {
            synchronized (ConfigManager.class) {
                if (instance == null) {
                    instance = new ConfigManager();
                }
            }
        }
        return instance;
    }

    private void load() {
        System.out.println("正在加载配置...");
        configMap.put("db.url", "jdbc:mysql://localhost:3306/mydb");
        configMap.put("db.maxConnections", "10");
    }

    public String get(String key) {
        return configMap.get(key);
    }
}
